// 挂号
function registered(name, callback) {
	console.log(name + "挂号中");
	setTimeout(function(){
		callback(4);
	}, 2000);
}
// 看医生
function seeDoctor(name, callback) {
	console.log(name + '正在看医生');
	setTimeout(function(){
		callback('一包板蓝根');
	}, 3000);
}
// 买药
function takeMedicine(name, callback) {
	console.log(name + "正在拿药");
	setTimeout(function(){
		callback();
	}, 1000);
}
// registered('小明', function(num){
// 	console.log('挂号成功, 号码牌:', num);
// 	seeDoctor('小明', function(m) {
// 		console.log('医生要小明拿药: ', m);
// 		takeMedicine('小明', function() {
// 			console.log('拿药成功，看病结束');
// 		});
// 	});
// })

function promisify(fun) {
	const promisifFun = (arg) => {
		return new Promise((resolve, rejest) => {
			fun(arg, resolve);
		});
	}
	return promisifFun;
}

const promisifyRegister = promisify(registered);
const promisifySeeDoctor = promisify(seeDoctor);
const promisifyTakemedicine = promisify(takeMedicine);

async function setup(name) {
	let num = await promisifyRegister(name);
	console.log('挂号成功, 号码牌:', num);
	let medicine = await promisifySeeDoctor(name);
	console.log('医生要小明拿药: ', medicine);
	await promisifyTakemedicine(name);
}
setup('小明');